<template>
    <div>
    <h1>公告显示页面</h1>
    名称<input type="text" v-model="page.name">
    <select v-model="page.types">
                    <option value="0">请选择</option>
                    <option v-for="s in tytpes" :value="s.fanid">{{s.fanname}}</option>
                </select>
                <input  type="button" value="查询" @click="cha">
    <table>
        <thead>
            <tr>
                <td><input  type="checkbox" v-model="sells" @change="quan"></td>
                <td>名称</td>
                <td>图片</td>
                <td>状态</td>
                <td>类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="m in data">
                <td><input  type="checkbox" v-model="idlisst" :value="m.dianid" ></td>
                <td>{{m.dianname}}</td>
                <td> <img style="height: 100px; width: 100px;" :src="'https://localhost:7075'+m.dianimg"></td>
                <td>{{m.diansates?"启用":"禁用"}}</td>
                <td>{{m.fanname}}</td>
                <td>
                    <input v-if="!m.diansates"  type="button" value="启用" @click="updatessate(m.dianid,true)">
                    <input v-else  type="button" value="禁用" @click="updatessate(m.dianid,false)">
                    <input   type="button" value="编辑" @click="Enid(m.dianid)">
                </td>
            </tr>
        </tbody>
    </table>
    </div>
    <input  type="button" value="首页" @click="Fanye(1)">
    <input  type="button" value="上一页" @click="Fanye(2)">
    <input  type="button" value="下一页" @click="Fanye(3)">
    <input  type="button" value="尾页" @click="Fanye(4)">
    一共{{paga.pcount}}页,一共{{paga.count}}行，每页{{page.size}}行，当前第{{page.index}}页
    <input  type="button" value="逻辑删除" @click="piluoDel()">

</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const sells=ref(false);
const idlisst=ref([0]);
const router=useRouter();


const quan=()=>
{
    if(sells.value)
{
    for(var i=0;i<data.value.length;i++)
{
    idlisst.value.push(data.value[i].dianid);
}
}
else{
    idlisst.value=[0]
}
}


const data=ref([{
    
    "dianid": 0,
  "dianname": "",
  "dianimg": "",
  "diansates": true,
  "fanid": 0,
  "fanname": ""

}])

const cha=()=>
{
    page.value.index=1;
    Getdata();
}



  const Fanye=(vid:any)=>
  {
   if(vid==1)
   {
    page.value.index=1;
    Getdata();
   }
   if(vid==2)
   {
    if( page.value.index>1)
   {
    page.value.index-=1;
    Getdata();
   }
    
   }
   if(vid==3)
   {
    if(page.value.index<paga.value.pcount)
    page.value.index+=1;
    Getdata();
   }

   if(vid==4)
   {
    page.value.index=paga.value.pcount;
    Getdata();
   }

  }

  onMounted(()=>
{
    getate();
    Getdata()
})
const tytpes=ref([{

"fanid": 0,
"fanname": ""
}

])
const getate=()=>
{
    axios.get("https://localhost:7075/api/fan/fanwei").then(res=>
        {
            tytpes.value=res.data;
        }
    )
}
const page=ref({
    index:1,
    size:3,
    name:"",
    types:null
})
const paga=ref({
    count:0,
    pcount:0
})

const Enid=(vid:any)=>

{
    router.push({path:"/Enid",query:{id:vid}})
}


const Getdata=()=>
{
    axios.get("https://localhost:7075/api/dian/fen",{params:page.value}).then(res=>
        {
            data.value=res.data.data;
            paga.value.count=res.data.count;
            paga.value.pcount=Math.ceil( paga.value.count/page.value.size);

        }
    )
}

const updatessate=(vid:any,vsates:any)=>
{
 axios.get("https://localhost:7075/api/dian/upsates",{params:{id:vid,sates:vsates}}).then(res=>
{
if(res.data>0)
{
    alert("状态修改成功");
    Getdata()
}
else{
    alert("状态修改失败");
}
}
 )
}

const piluoDel=()=>
{
    if(confirm("确认删除吗?"))
{
    axios.delete("https://localhost:7075/api/dian/piluoDel",{params:{idssing:idlisst.value.toString()}}).then(res=>
        {
            if(res.data>0)
        {
            alert("逻辑删除成功");
            Getdata()
        }
        else{
            alert("逻辑删除失败");
            return;
        }
        }
    )
}
    
}



</script>

<style scoped>

</style>